using System.Collections.Generic;
using System.Web.Security;
using SpiderMaster;

namespace SpiderMaster.AspNet.TradingSystem
{
    public sealed partial class TradingCenterMember
    {
        /// <summary> Gets the errors. 
        /// (If user, User specific messages are returned)
        /// (If administrator, Admin Specific are returned)
        /// </summary>
        /// <returns></returns>
        [ReganSchroder(5, 10, 2009)]
        private List<string> GetErrors()
        {
            List<string> ErrorContent = new List<string>();

            if (Profile.HasErrors)
                ErrorContent.Add(Profile.Errors);

            if (AspNetMembershipErrors.IsNotNull())
                ErrorContent.Add(AspNetMembershipErrors);

            return ErrorContent;
        }

        /// <summary> Gets the user ASP net membership errors. </summary>
        /// <returns></returns>
        [ReganSchroder(5, 10, 2009)]
        private List<string> AspNetMembershipErrors
        {
            get
            {
                List<string> ErrorContent = new List<string>();

                if (TradingCenterMember.Current.IsAdministrator)
                {
                    if (!this.AspNetMembership.IsApproved)
                        ErrorContent.Add("AspNet: Is Not Approved.");
                    if (this.AspNetMembership.IsLockedOut)
                        ErrorContent.Add("AspNet: Is Locked Out.");

                    MembershipUserCollection MUC = Membership.GetAllUsers();
                    int EmailCount = -1;
                    foreach (MembershipUser MU in MUC)
                        if (MU.Email == AspNetMembership.Email)
                            EmailCount++;

                    // TODO:
                    //if (!EmailCount.IsNoMoreThan(1))
                    //    ErrorContent.Add("AspNet: Found " + (EmailCount) + " Matching Emails.");
                }

                return ErrorContent;
            }
        }
    }
}